package com.example.yiqiuser.controller;

import com.example.yiqiuser.entity.Scenic;
import com.example.yiqiuser.service.CommonFileHandlerService;
import com.example.yiqiuser.service.ScenicService;
import com.example.yiqiuser.util.Page;
import com.example.yiqiuser.util.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @create by: 周文达 (3220083246@qq.com)
 * @description:
 * @create time: 2023/4/12 22:45
 * @return
 */
@RestController
@RequestMapping("scenic")
public class ScenicController extends BaseController {

    @Resource
    private CommonFileHandlerService commonFileHandlerService;

    /**
     * 文件上传操作
     *        必须使用@RequestParam绑定上传对象，否则文件上传不了  里面的名称必须和前端对应
     * @param file1   MultipartFile  该类是springmvc封装的获取上传文件的对象
     * @return
     */
    @PostMapping("uploadFile")
    public Result uploadFile(@RequestParam("file2") MultipartFile file1){
        //调用封装的服务接口 进行文件上传
        return success(commonFileHandlerService.uploadFile(file1,"Project/user"));
    }
    /**
     * 分页带参查询
     * @param page
     * @return
     */
    @PostMapping("queryPage")
    public Result queryPage(@RequestBody Page<Scenic> page){
        return success(scenicService.queryPage(page));
    }
    @Resource
    //依赖注入
    private ScenicService scenicService;
    @PostMapping("queryAll")
    public  Result queryAll(){
        return success(scenicService.queryAll());
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("queryById")
    public Result queryById(Integer id){
        /*System.out.println(id);*/
        return success(scenicService.queryById(id));
    }

    /**
     * 添加
     * @param scenic
     * @return
     */
    @PostMapping("add")
    public  Result add(@RequestBody Scenic scenic){
        return success(scenicService.add(scenic));
    }

    /**
     * 更新
     * @param scenic
     * @return
     */
    @PostMapping("update")
    public Result update(@RequestBody Scenic scenic){
        return success(scenicService.update(scenic));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("deleteById")
    public Result deleteById(Integer id){
        return success(scenicService.deleteById(id));
    }

    /**
     * 根据票数降序排列带参查询
     * @param page
     * @return
     */
    @PostMapping("recommendShow")
    public Result recommendShow(@RequestBody Page<Scenic> page){
        /*System.out.println("------------page(参数):"+page+"------------");*/
        return success(scenicService.recommendShow(page));
    }

    /**
     * 根据票数降序排列带参查询
     * @param page
     * @return
     */
    @PostMapping("priceShow")
    public Result priceShow(@RequestBody Page<Scenic> page){
        /*System.out.println("------------page(参数):"+page+"------------");*/
        return success(scenicService.priceShow(page));
    }

}
